//
//  AnswerSortViewController.m
//  Hxcsfw
//
//  Created by qiysoft on 2017/12/27.
//  Copyright © 2017年 企友软mac. All rights reserved.
//

#import "AnswerSortViewController.h"
#import "JSWTViewController.h"
#import "CSSWViewController.h"
#import "BSZNViewController.h"
#import "XYSegmentView.h"

@interface AnswerSortViewController ()<UIScrollViewDelegate,XYSegmentViewDelegate>

@property (nonatomic,strong) UIScrollView *homeScrollView;
@property (nonatomic,strong) XYSegmentView *titScrollView;

@end

@implementation AnswerSortViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"问题分类";
    //高度在JSWTViewController、CSSWViewController、BSZNViewController各自类seachView的高度修改
    JSWTViewController *JSWTVC = [[JSWTViewController alloc]init];
    [self addChildViewController:JSWTVC];
    
    CSSWViewController *CSSWVC = [[CSSWViewController alloc]init];
    [self addChildViewController:CSSWVC];
    
    BSZNViewController *BSZNVC = [[BSZNViewController alloc]init];
    [self addChildViewController:BSZNVC];
    
    [self initScrollViewItem];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 初始化scrollView上的页面
- (void)initScrollViewItem {

    if (XIPHONE) {
        _titScrollView = [[XYSegmentView alloc]initWithFrame:CGRectMake(0, 94, WSCREENH_WIDTH, 44)];
    } else {
        _titScrollView = [[XYSegmentView alloc]initWithFrame:CGRectMake(0, 64, WSCREENH_WIDTH, 44)];
    }
    _titScrollView.delegate = self;
    _titScrollView.titleArray = @[@"技术问题",@"财税实务",@"办税指南"];
    _titScrollView.titleSpacing = 0;
    _titScrollView.labelFont = [UIFont systemFontOfSize:15];
    _titScrollView.bottomLabelTextColor = [UIColor blackColor];
    _titScrollView.topLabelTextColor = [UIColor colorWithRed:0.22 green:0.6 blue:0.9 alpha:1];
    _titScrollView.selectedBackgroundColor = [UIColor whiteColor];
    _titScrollView.selectedBgViewCornerRadius = 20;
    _titScrollView.sliderHeight = 3;
    _titScrollView.sliderColor = [UIColor colorWithRed:0.22 green:0.6 blue:0.9 alpha:1];
    _titScrollView.sliderTopMargin = 3;
    _titScrollView.duration = 0.3;
    [self.view addSubview:_titScrollView];
    
    CGFloat tableViewW = WSCREENH_WIDTH;
    CGFloat tableViewH = self.view.height - CGRectGetMaxY(_titScrollView.frame)+72;

    if (XIPHONE) {
        _homeScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titScrollView.frame), tableViewW, WSCREENH_HEIGHT - 160)];
    } else {
        _homeScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titScrollView.frame), tableViewW, WSCREENH_HEIGHT - 44)];
    }
    
    _homeScrollView.delegate = self;
    _homeScrollView.backgroundColor = [UIColor clearColor];
    _homeScrollView.contentSize = CGSizeMake(tableViewW * 3, tableViewH);
    _homeScrollView.pagingEnabled = YES;
    _homeScrollView.bounces = NO;
    [self.view addSubview:_homeScrollView];
    
    NSArray *color = @[[UIColor whiteColor],[UIColor whiteColor],[UIColor whiteColor]];
    for (int i = 0; i < self.childViewControllers.count; i++) {
        UIViewController *vc = self.childViewControllers[i];
        vc.view.frame = CGRectMake(i * tableViewW, 0, tableViewW, WSCREENH_HEIGHT-44);
        vc.view.backgroundColor = color[i];
        [_homeScrollView addSubview:vc.view];
    }
    _titScrollView.outScrollView = _homeScrollView;
    
}

- (void)buttonClick:(NSInteger)index {
    [_homeScrollView setContentOffset:CGPointMake(self.view.width * index, 0) animated:NO];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"LoginBack" object:nil];
}

@end
